package com.iot.comprehensive.face.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.Contact;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

//@Configuration标注在类上，相当于把该类作为spring的xml配置文件中的，作用为：配置spring容器
@Configuration
@EnableSwagger2 //标记项目启用
public class SwaggerConfiguration {
    @Bean
    public Docket createRestApi(){
        return new Docket(DocumentationType.SWAGGER_2)//文档类型
                .apiInfo(this.apiInfo()) //设置Api信息
                .select()//扫描controller包路径，获得api接口
                .apis(RequestHandlerSelectors.basePackage("com.iot.comprehensive.face.controller"))
                .paths(PathSelectors.any())
                .build();
    }

    /*创建API信息*/
    private ApiInfo apiInfo() {
        return new ApiInfoBuilder()
                .title("测试接口文档示例")
                .description("物联网综合")
                .version("1.0.0")
                .contact(new Contact("物联网综合","localhost:21625","1271107612@qq.com"))
                .build();
    }
}
